package main

import (
	"net/http"
	"strings"
)

func (self *Site) ValidLogin(resp http.ResponseWriter, req *http.Request) *WUser {
	err := req.ParseForm()
	if err == nil {
		user1 := req.FormValue("name")
		pwd1 := req.FormValue("pwd")
		ip1, _ := req.Cookie("login")
		if len(user1) == 0 || len(pwd1) == 0 {
			return nil
		}
		return self.VerifyUser(user1, pwd1, ip1.Value)
	} else {
		return nil
	}
}

func (self *Site) ValidLogined(resp http.ResponseWriter, req *http.Request) *WUser {
	cookie1, err := req.Cookie("logined")
	if err != nil {
		return nil
	}
	vs1 := strings.Split(cookie1.Value, "@")
	if len(vs1) < 2 {
		return nil
	}
	ip1, err := req.Cookie("login")
	if err != nil {
		return nil
	}
	return self.VerifyUID(vs1[0], vs1[1], ip1.Value)
}
